<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>试卷生成及阅卷系统列表页</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<!--数据与分页-->
<div class="user_table_div">
    <table class="layui-hide" id="exam_table" lay-filter="exam_table"></table>
    <!--分页相关 View-->
    <div id="laypage" class="layui-laypage-btn"></div>
</div>
<div class="panel panel-default operation_user" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="deptInfo" style="width: 1000px;margin-top: 10px">
            <input name="id" hidden/>
            <input name="examId" hidden>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block title">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">题目</label>
                <div class="layui-input-block topicTile">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分值</label>
                <div class="layui-input-block fraction">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">答案</label>
                <div class="layui-input-block option">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">得分</label>
                <div class="layui-input-block">
                    <input type="number" name="grade" placeholder="得分" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-xs" lay-event="edit">评分</a>
</script>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/xm-select.js"></script>
<script>
    layui.use(['jquery', 'form', 'table', 'laypage', 'layer', 'laydate', 'tree', 'transfer', 'layedit'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var laypage = layui.laypage
        var layer = layui.layer;
        var laydate = layui.laydate;

        var searchParam = {
            current: 1,
            size: 10,
            /*以下为多条件查询参数*/
            name: null
        }

        /**
         *  加载分页数据
         */
        function loadPageInfo() {
            CoreUtil.sendAjax("/exam/answerResults/page", searchParam, function (res) {
                //初始化分页器
                laypageTable(res.total, searchParam.current);
                //初始化渲染数据
                loadTable(res.records);
                if (res.records != null) {
                    loadTable(res.records);
                }
            }, "GET", false, function (res) {
                //用户列表接口无权限回调
                layer.msg("抱歉！您暂无获取用户列表的权限");
                var noAuthorityData;
                noAuthorityData = [];
                loadTable(noAuthorityData);
            });
        }

        //渲染分页插件
        var laypageTable = function (count, currentPage) {
            laypage.render({
                elem: 'laypage'
                , count: count
                , limit: searchParam.size
                , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                , curr: location.hash.replace('#!currentPage=', '')     //获取起始页
                , hash: 'currentPage'                                   //自定义hash值
                , jump: function (obj, first) {
                    if (!first) {
                        searchParam.current = obj.curr;
                        searchParam.size = obj.limit;
                        loadPageInfo();
                    }
                }
            });
        };
        //渲染table
        var loadTable = function (data) {
            //展示已知数据
            table.render({
                elem: '#exam_table'
                // 这个 data 为数组数据，直接 放到 data 上即可。
                , data: data
                , even: true
                , limit: data.length
                , limits: [10, 20, 30, 40, 50]
                , cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'id', title: 'ID', width: 60, sort: true},
                        {field: 'examName', title: '考试', width: 430},
                        {field: "topicTitle", title: "题目名", width: 300},
                        {width: 600, toolbar: "#tool", title: '操作'}
                    ]
                ]
            });
        };
        loadPageInfo();

        // 操作工具栏 点击赋予角色事件事件
        table.on('tool(exam_table)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'edit':
                    $(".user_table_div").hide();
                    $(".operation_user").show();
                    $(".title").text(data.topicTitle)
                    $(".topicTile").html(data.topicContent)
                    $(".fraction").text(data.fraction)
                    $(".option").html(data.option)
                    $("input[name=grade]").val("")
                    $("input[name=id]").val(data.id)
                    $("input[name=examId]").val(data.examId)
                    form.render();
                    break;
            }
        });

        //监听提交 新增和编辑  保存按钮
        form.on('submit(submit)', function (data) {
            //新增
            CoreUtil.sendAjax("/exam/answerResults", JSON.stringify(data.field), function (res) {
                //显示表格
                loadPageInfo();
                $(".user_table_div").show();
                //隐藏编辑窗口
                $(".operation_user").hide();
                // 刷新页面，但是不管事儿
                $(".layui-laypage-btn").click();
            }, "POST", false, function (res) {
                //新增试卷无权限提示
                layer.msg("抱歉！您暂无新增试卷的权限");
            });
            return false;
        })

    });
</script>
</html>